
class Utils {
    static dict = {
        "string": "[object String]",
        "object": "[object Object]",
        "array": "",
    }

    static is2type(value, type = "string") {
        return Object.prototype.toString.call(value) === Utils.dict[type];
    }

    /**
     * 参考vue-cli实现方式
     * 使用.call改变this指向
     * 传入data数据,通过with关键字改变作用域
     * @param {string} attrs 
     */
    static value2props(attrs) {
        let NewVals = "";
        const fn2with = new Function('data', 'with (data) { return ' + attrs + '}');
        try {
            NewVals = fn2with(this.vm);
        } catch (error) {
            console.error("this is wrong props");
        }
        return NewVals;
    }
}